function Echart(id, title, type, xdata, data) {
    var myChart = echarts.init(document.getElementById(id))
    var dataOption
    var option = {
        title: {
            text: title,
            left: 'center',
        },
        tooltip: {},
        xAxis: {
            data: xdata,
            axisTick: {
                show: false, //刻度线
            },
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: '{value} 人',
            },
            axisTick: {
                show: false, //刻度线
            },
        },
        series: [
            {
                type: type,
                data: data,
                radius: '50%',
                smooth: true,
                lineStyle: {
                    color: '#4587f0',
                },
                areaStyle: {
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [
                            {
                                offset: 0,
                                color: 'rgba(58,132,255, 0.5)', // 0% 处的颜色
                            },
                            {
                                offset: 1,
                                color: 'rgba(58,132,255, 0)', // 100% 处的颜色
                            },
                        ],
                        global: false, // 缺省为 false
                    },
                },
            },
        ],
    }
    var pieOption = {
        title: {
            text: '饼图数据展示',
            left: 'center',
        },
        tooltip: {
            trigger: 'item',
        },
 
        series: [
            {
                type: 'pie',
                radius: '50%',
                data: data,
            },
        ],
    }
    //使用制定的配置项和数据显示图表
    var categoryOption = {
        xAxis: {
            type: type,
            title: title,
            data: xdata,
            axisTick: {
                show: false, //刻度线
            },
        },
        yAxis: {
            type: 'value',
            axisTick: {
                show: false, //刻度线
            },
        },
        series: [
            {
                data: data,
                type: 'bar',
                itemStyle: {
                    color: '#a90000',
                },
            },
        ],
    }
    switch (type) {
        case 'line':
            dataOption = option
            break
        case 'pie':
            dataOption = pieOption
            break
        case 'category':
            dataOption = categoryOption
            break
        default:
            break
    }
    myChart.setOption(dataOption)
}
function animate(obj, target, callback) {
    clearInterval(obj.timer)
    obj.timer = setInterval(function () {
        //步长 = （目标值-现在位置）/10  取整
        let step = (target - obj.offsetLeft) / 10
        //大于0向上取整   小于0向下取整
        step = step > 0 ? Math.ceil(step) : Math.floor(step)
        if (obj.offsetLeft == target) {
            //停止动画定时器
            clearInterval(obj.timer)
            //判断回调函数是否存在
            if (callback) {
                callback()
            }
        }
        obj.style.left = obj.offsetLeft + step + 'px'
    }, 15)
}
